<!--代码逻辑和样式库-->
<script src="./car-list.component.js"></script>
<style src="./car-list.scss" scoped lang="scss"></style>

<template>
  <div>
    <!-- 搜索区域 -->
    <div class="search-container">
      <el-form label-position="top" :inline="true">
        <el-row type="flex">
          <el-col :span="24" class="aq-vertical-middle">
            <el-input v-if="codesCheck.indexOf('Query') !== -1" v-model="searchCriteria.queryStr" placeholder="请输入车牌或名称搜索" class="keyword" clearable @keyup.enter.native="search()" />
            <el-select v-model="searchCriteria.transStatus" placeholder="请选择运输状态" clearable class="aq-margin-left-4">
              <el-option v-for="(item,index) in carStatus" :key="index" :label="item.itemName" :value="item.itemValue">
              </el-option>
            </el-select>
            <el-select v-model="searchCriteria.transportId" placeholder="请选择运输单位" clearable class="aq-margin-left-8">
              <el-option v-for="(item,index) in companies" :key="index" :label="item.text" :value="'' + item.id">
              </el-option>
            </el-select>
            <el-button v-waves v-if="codesCheck.indexOf('Query') !== -1" type="primary" icon="el-icon-search" class="aq-margin-left-8" @click="search()">
              查询
            </el-button>
            <el-button v-waves v-if="codesCheck.indexOf('Query') !== -1" type="warning" icon="el-icon-refresh" @click="reset()">
              重置
            </el-button>
            <el-button v-waves v-if="codesCheck.indexOf('Create') !== -1" type="success" icon="el-icon-edit" @click="openEditDialog('create')">
              新增
            </el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 内容区域 -->
    <div class="content-container aq-margin-top-16">
      <!--用户角色table-->
      <el-table :data="data" border fit highlight-current-row @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" fixed></el-table-column>
        <el-table-column prop="transportStatus" label="运输状态" />
        <el-table-column prop="vehicleName" label="车辆名称" />
        <el-table-column prop="licensePlate" label="车牌号码">
          <template slot-scope="scope">
            <el-link type="primary" @click="showCarDetailDialog(scope.row)">{{ scope.row.licensePlate }}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="brandName" label="车辆品牌" />
        <el-table-column prop="modelNo" label="车辆型号" />
        <el-table-column prop="loadingCapacity" label="载重量" />
        <el-table-column prop="medium" label="介质类型" />
        <el-table-column prop="compName" label="运输单位" />
        <el-table-column prop="contact" label="联系人" />
        <el-table-column prop="phone" label="联系方式" />
        <el-table-column prop="isRelated" label="是否关联设备" width="70px">
          <template slot-scope="scope">
            {{ scope.row.isRelated == '1' ? '已关联' : '未关联' }}
          </template>
        </el-table-column>
        <el-table-column prop="Serial No." label="设备Serial No." width="155px">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.relatedList.slice(0, 3)" :key="index">{{ item.text }}</div>
            <div v-if="scope.row.relatedList.length > 3">...</div>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="155px" />
        <el-table-column prop="text" label="操作" width="240px" align="center" fixed="right">
          <template slot-scope="scope">
            <el-link v-if="codesCheck.indexOf('Edit') != -1" icon="el-icon-edit" type="primary" @click="openEditDialog('edit', scope.row)">编辑</el-link>
            <el-link class="aq-margin-left-16" icon="el-icon-connection" size="mini" type="success" @click="showCarDialog(scope.row)">关联设备</el-link>
            <el-link class="aq-margin-left-16" v-if="scope.row.isEnable == '1'" icon="el-icon-delete" size="mini" type="danger" @click="toggleCarStatus(scope.row.objectId, '0')">停用</el-link>
            <el-link class="aq-margin-left-16" v-else icon="el-icon-open" size="mini" type="warning" @click="toggleCarStatus(scope.row.objectId, '1')">启用</el-link>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页插件 -->
      <pagination v-show="totalNum > 0" :total="totalNum" :page.sync="pageNum" :limit.sync="recordNum" @pagination="getDataList" />
    </div>
    <!-- 创建/编辑角色 -->
    <el-dialog :title="dialogTitle" :visible.sync="editDialogVisible" width="800px">
      <el-form ref="dataForm" :model="editForm" :rules="editRules" label-position="left" label-width="100px">
        <el-row :gutter="20">
          <el-col :xs="12" :sm="12" :lg="12">
            <el-form-item prop="vehicleName" label="车辆名称">
              <el-input v-model="editForm.vehicleName" class="el-input-width" clearable maxlength="30" show-word-limit />
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="12">
            <el-form-item prop="licensePlate" label="车牌号码">
              <el-input v-model="editForm.licensePlate" class="el-input-width" clearable />
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="12">
            <el-form-item label="车牌品牌">
              <el-select v-model="editForm.brandInfo.brandId" clearable class="aq-width-full" @change="handleCategoryChange">
                <el-option v-for="item in categories" :key="item.objectId" :label="item.brandName" :value="item.objectId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="12">
            <el-form-item label="车牌型号">
              <el-select v-model="editForm.brandInfo.modelId" clearable class="aq-width-full">
                <el-option v-for="item in categoryItems" :key="item.id" :label="item.text" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="12">
            <el-form-item prop="enumMedium" label="介质类型">
              <el-select v-model="editForm.enumMedium" clearable class="aq-width-full">
                <el-option v-for="item in jzItems" :key="item.itemValue" :label="item.itemName" :value="item.itemValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="12">
            <el-form-item prop="loadingCapacity" label="载重量">
              <el-input v-model="editForm.loadingCapacity" class="el-input-width" clearable />
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="12">
            <el-form-item prop="transportId" label="运输单位">
              <el-select v-model="editForm.transportId" placeholder="请选择运输单位" clearable class="aq-width-full">
                <el-option v-for="item in companies" :key="item.id" :label="item.text" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="12" :sm="12" :lg="12">
            <el-form-item prop="contact" label="联系人">
              <el-input v-model="editForm.contact" class="el-input-width" clearable maxlength="10" show-word-limit />
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="12">
            <el-form-item prop="phone" label="联系方式">
              <el-input v-model="editForm.phone" class="el-input-width" clearable maxlength="11" show-word-limit />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" class="aq-vertical-middle">
            <el-form-item label="上传照片:">
              <el-upload class="avatar-uploader" :action="file_url + 'file/upload'" :show-file-list="false" :on-success="handleAvatarSuccess">
                <img v-if="editForm.vehiclePhoto" :src="file_url + editForm.vehiclePhoto" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
              <i v-if="editForm.vehiclePhoto" @click="handleAvatarRemove()" class="el-icon-delete avatar-delete-icon"></i>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :lg="24" align="center">
            <el-button v-if="!editForm.objectId" type="primary" class="action-btn" @click="save()">立即创建</el-button>
            <el-button v-else type="primary" class="action-btn" @click="save()">提交</el-button>
            <el-button class="action-btn" @click="editDialogVisible = false">取消</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!-- 显示关联车辆 -->
    <select-device v-if="showSelectCarDialog" :show-dialog.sync="showSelectCarDialog" @submit="setDevices" :vehicle-id="selectedData.objectId"></select-device>
    <!-- 显示车辆详情 -->
    <car-detail v-if="showSelectCarDetailDialog" :show-dialog.sync="showSelectCarDetailDialog" :vehicle-id="vehicleId" :equip-id="equipId"></car-detail>
  </div>
</template>
